#!/usr/bin/perl

#OBJECT DEFINITION
{ package DataBank;

	# PERL MODULES WE WILL BE USING
	use DBI;
	use DBD::mysql;

	# ALLOCATE VARIABLE
	sub new {
		my $self = {};
		bless $self;
		$self->{PLATFORM};
		$self->{DATABASE};
		$self->{HOST};
		$self->{PORT};
		$self->{TABLENAME};
		$self->{USER};
		$self->{PW};
		warn "CREATING " . \$self;
		return bless $self;
	}

	# DESALLOCATE VARIABLES
	sub DESTROY {
		my $self = shift;
		warn "DESTROYING $self";
	}

	# CONECT TO THE DB
	sub ConnectDB {
		my $self = shift;
		$self->Reconfigure($self,"mysql","store","localhost","3306","inventory","betaTester","password");

		#DATA SOURCE NAME
		$dsn = "dbi:".$self->{PLATFORM}.":".$self->{DATABASE}.":".$self->{HOST}.":".$self->{PORT};
		print "dsn = ".$dsn."\n";

		# PERL DBI CONNECT (RENAMED HANDLE)
		$dbstore = DBI->connect($dsn, $self->{USER}, $self->{PW}) or die "Unable to connect: $DBI::errstr\n";
	}

	# CONFIG VARIABLES
	sub Reconfigure {
		my $self = shift;
		$a = shift; #????????????
		$self->{PLATFORM} = shift;
		$self->{DATABASE} = shift;
		$self->{HOST} = shift;
		$self->{PORT} = shift;
		$self->{TABLENAME} = shift;
		$self->{USER} = shift;
		$self->{PW} = shift;
		#print "REConfig:".$self->{PLATFORM}.":".$self->{DATABASE}.":".$self->{HOST}.":".$self->{PORT}.":".$self->{TABLENAME}.":".$self->{USER}.":".$self->{PW}."\n"
	}

	# RECEIVE QUERYS
	sub Query{
		my $self = shift;
		$self->{QUERY} = shift;
		# PREPARE THE QUERY STRING		
		$query_handle = $dbstore->prepare($self->{QUERY});

		# EXECUTE THE QUERY
		$query_handle->execute();
		return $query_handle;
	}
 sub name {
        my $self = shift;
        if (@_) { $self->{NAME} = shift }
        return $self->{NAME};
    }
}
